﻿Ext.define('app.prm.product.Detail', {
    extend: 'Ext.panel.Panel',
    layout: 'border',
    controller: 'product',
    requires: ['app.prm.product.ProductController'],
    initComponent: function () {
        var me = this;
        me.productId = me.paramsId;
        me.items = [me.getNorth(), me.getCenter()];
        me.callParent();
    },
    listeners: {
        afterrender: function (me) {
            App.AjaxGet('/api/services/app/product/Get?productId=' + me.productId, function (data) {
                me.getBasicInfo().getForm().setValues(data.result);
                console.log(data.result.substanceMolPngBase64);
                showImg(me.getMolImage().getId(), data.result.substanceMolPngBase64, 10, 'middle');
            });
        }
    },
    getNorth: function () {
        var me = this;
        if (!this.north) {
            this.north = new Ext.panel.Panel({
                border: false,
                region: 'north',
                height: 200,
                layout: 'column',
                items: [me.getMolImage(), me.getBasicInfo()]
            });
        }
        return this.north;
    },
    getMolImage: function () {
        var me = this;
        if (!me.molImages) {
            me.molImages = new Ext.panel.Panel({
                border: false,
                height: 200,
                columnWidth: .3,
                html: 'image'
            });
        }
        return me.molImages;
    },
    getBasicInfo: function () {
        var me = this;
        if (!me.basicInfo) {
            me.basicInfo = new Ext.form.Panel({
                border: false,
                layout: 'form',
                defaults: {
                    anchor: '100%',
                    xtype: 'displayfield'
                },
                columnWidth: .7,
                items: [
                    {
                        fieldLabel: '产品号',
                        name: 'code'
                    },
                    {
                        fieldLabel: '中文名',
                        name: 'substanceCnName'
                    },
                    {
                        fieldLabel: '英文名',
                        name: 'substanceEnName'
                    },
                    {
                        fieldLabel: '分子式',
                        name: 'substanceFormula'
                    },
                     {
                         fieldLabel: '分子量',
                         name: 'substanceMolecularWeight'
                     },
                     {
                         fieldLabel: 'CAS',
                         name: 'substanceCAS'
                     },
                    {
                        fieldLabel: '高风险',
                        name: 'substanceHighRisk'
                    },
                    {
                        fieldLabel: '备注',
                        name: 'substanceNote'
                    }
                ]
            });
        }
        return me.basicInfo;
    },
    getCenter: function () {
        var me = this;
        if (!this.centerPanel) {
            this.centerPanel = new Ext.panel.Panel({
                region: 'center',
                border: false,
                items: [
                   Ext.create("app.prm.product.Phase", { productId: me.productId }),
                    Ext.create("app.prm.product.Document", { productId: me.productId })
                ]
            });
        }
        return this.centerPanel;
    },
    getProjectGrid: function () {
        var me = this;
        if (!this.projectGrid) {
            this.projectGrid = new Ext.grid.Panel({
                viewConfig: {
                    enableTextSelection: true //可以复制单元格文字
                },
                title: '项目列表',
                forceFit: false,
                //autoHeight: true,
                multiColumnSort: true,
                store: Ext.create("app.ux.PrmStore", {
                    url: '/api/services/app/project/GetByProductId', filter: { productId: me.productId }, remoteSort: false,
                    sorters: [{
                        //先按年龄降序  
                        property: 'targetEndDate',
                        direction: 'DESC'
                    }]
                }),
                columns: [
                    { header: localize('ProjectNo'), dataIndex: 'projectNo' },
                    { header: localize('ProjectName'), dataIndex: 'projectName' },
                    { header: localize('ProductNo'), dataIndex: 'productNo' },
                    { header: localize('Customer'), dataIndex: 'customer' },
                    { header: localize('CustomerCode'), dataIndex: 'customeCode' },
                    { header: '事业部', dataIndex: 'business', hidden: true },
                    { header: localize('RdCenter'), dataIndex: 'rdCenter', hidden: true },
                    { header: localize('Laboratory'), dataIndex: 'laboratory', hidden: true },
                    { header: localize('PlanStartDate'), dataIndex: 'planStartDate' },
                    { header: localize('PlanEndDate'), dataIndex: 'planEndDate' },
                    { header: localize('RequiredCompleteDate'), dataIndex: 'targetEndDate' }
                ],
                listeners: {
                    rowdblclick: 'onDbClick'
                }
            });
        }
        return this.projectGrid;
    }
});